package com.tiantianfresh.admin.util;

import java.util.List;

/**
 * @author FANGAO
 * @date 2021/10/4 - 下午 17:19
 */
public class Page<T> {
    private List<T> datas;//数据库数值

    private int pageSize=1;//页容量1

    private int currentPageNo= 1;//当前页

    private int totalPageCount=0;//总页数

    private int totalCount=0;//总条数1

    public Page(int pageSize, int currentPageNo, int totalCount) {
        setPageSize(pageSize);
        setTotalCount(totalCount);
        setCurrentPageNo(currentPageNo);
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }

    public int getPageSize() {
        return pageSize;
    }

    private void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPageNo() {
        return (currentPageNo - 1) * pageSize;
    }

    private void setCurrentPageNo(int currentPageNo) {
        totalPageCount();
        if (currentPageNo<=1){
            this.currentPageNo=1;
        }else if (currentPageNo>=this.totalPageCount){
            this.currentPageNo=this.totalPageCount;
        }else{
            this.currentPageNo=currentPageNo;
        }
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public int getTotalCount() {
        return totalCount;
    }

    private void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    private void totalPageCount(){
        if (totalCount%pageSize==0){
            totalPageCount= totalCount/pageSize ;
        }
        else if (totalCount%pageSize>0) {
            totalPageCount= totalCount/pageSize+1;
        }else{
            totalPageCount=0;
        }
    }
}
